<?php
@session_start();
 $con = mysqli_connect("127.0.0.1","root","","posts");
 if($_FILES['avatar']['size']>0){
     $basename = basename($_FILES['avatar']['name']);
     $uploadfile = "../img/".$basename;
     move_uploaded_file($_FILES['avatar']['tmp_name'], $uploadfile);

     $avatar = $basename;
     $name = $_POST['username'];
     $gender = $_POST['gender'];
     $birthday  = $_POST['birthday'];
     $email = $_POST['email'];
     $address = $_POST['address'];
    
    
     mysqli_query($con,"UPDATE info set avatar='$avatar',name='$name',gender='$gender',birthday='$birthday',email='$email',address='$address'");
     mysqli_query($con,"update posts set avatar='$avatar' where name='$name'");
     $_SESSION['user'] = $name;
     mysqli_close($con);
     
     echo "<script>window.location='../html/posts.html'</script>";
 }else{
     $name = $_POST['username'];
     $gender = $_POST['gender'];
     $birthday  = $_POST['birthday'];
     $email = $_POST['email'];
     $address = $_POST['address'];
     
     
     mysqli_query($con,"UPDATE info set name='$name',gender='$gender',birthday='$birthday',email='$email',address='$address'");
     
     $_SESSION['user'] = $name;
     mysqli_close($con);
     
     echo "<script>window.location='../html/posts.html'</script>";
 }
?>